{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Find Numbers with Even Number of Digits"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: findNumbers"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #统计位数为偶数的数字"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个整数数组&nbsp;<code>nums</code>，请你返回其中位数为&nbsp;<strong>偶数</strong>&nbsp;的数字的个数。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>nums = [12,345,2,6,7896]\n",
    "<strong>输出：</strong>2\n",
    "<strong>解释：\n",
    "</strong>12 是 2 位数字（位数为偶数）&nbsp;\n",
    "345 是 3 位数字（位数为奇数）&nbsp;&nbsp;\n",
    "2 是 1 位数字（位数为奇数）&nbsp;\n",
    "6 是 1 位数字 位数为奇数）&nbsp;\n",
    "7896 是 4 位数字（位数为偶数）&nbsp;&nbsp;\n",
    "因此只有 12 和 7896 是位数为偶数的数字\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>nums = [555,901,482,1771]\n",
    "<strong>输出：</strong>1 \n",
    "<strong>解释： </strong>\n",
    "只有 1771 是位数为偶数的数字。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= nums.length &lt;= 500</code></li>\n",
    "\t<li><code>1 &lt;= nums[i] &lt;= 10^5</code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [find-numbers-with-even-number-of-digits](https://leetcode.cn/problems/find-numbers-with-even-number-of-digits/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [find-numbers-with-even-number-of-digits](https://leetcode.cn/problems/find-numbers-with-even-number-of-digits/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[12,345,2,6,7896]', '[555,901,482,1771]']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        count=0\n",
    "        for i in nums:\n",
    "            if len(str(i))%2==0:\n",
    "                count+=1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        ans = 0\n",
    "        for i in nums:\n",
    "            if len(str(i)) % 2 == 0:\n",
    "                ans += 1\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        ans=0\n",
    "        for i in nums:\n",
    "            if len(str(i))%2==0:\n",
    "                ans+=1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        return sum(len(str(i))%2 == 0 for i in nums)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        def wei(x):\n",
    "            x = str(x)\n",
    "            return len(x)%2==0\n",
    "        count = 0\n",
    "        for i in nums:\n",
    "            if wei(i):\n",
    "                count = count+1\n",
    "        return count\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        ans = 0\n",
    "        for n in nums:\n",
    "            if (n >= 10 and n < 100) or (n >= 1000 and n < 10000) or n == 100000:\n",
    "                ans += 1\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        return sum(1 for num in nums if len(str(num)) % 2 == 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "\n",
    "     ans=0\n",
    "     for num in nums:\n",
    "        if len(str(num))%2==0:\n",
    "         ans +=1\n",
    "     return ans  \n",
    "\n",
    "\n",
    " \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        res=0\n",
    "        for i in nums:\n",
    "            if(len(str(i))%2==0):\n",
    "                res+=1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        n=0\n",
    "        for i in nums:\n",
    "            if len(str(i))%2==0:\n",
    "                n=n+1\n",
    "        return n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        i = 0\n",
    "        for data in nums:\n",
    "            if len(str(data)) % 2 == 0:\n",
    "                i += 1\n",
    "        return i \n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        res=0\n",
    "        for x in nums:\n",
    "            ans=0\n",
    "            while x:\n",
    "                ans+=1\n",
    "                x //=10\n",
    "            if ans % 2==0:\n",
    "                res+=1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        ans = 0\n",
    "        for n in nums:\n",
    "            if len(str(n)) % 2 == 0:\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        return len([i for i in nums if len(str(i))%2==0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        res = 0\n",
    "        for i in nums:\n",
    "            if len(str(i)) % 2 == 0:\n",
    "                res += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        return sum(int(log10(i)) % 2 for i in nums)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        ans=0\n",
    "        for num in nums:\n",
    "            if len(str(num))%2==0:\n",
    "                ans+=1\n",
    "           \n",
    "        return ans\n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        res = 0\n",
    "        for num in nums:\n",
    "            if len(str(num)) % 2 == 0:\n",
    "                res += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        return sum(1 for num in nums if len(str(num)) % 2 == 0)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        return sum(1 for num in nums if len(str(num)) % 2 == 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        res = 0\n",
    "        for nu in nums:\n",
    "            if len(str(nu)) % 2 == 0:\n",
    "                res += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        return sum(1 for num in nums if len(str(num))%2==0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        ans=0\n",
    "        for num in nums:\n",
    "            if 10<=num<=99 or 1000<=num<=9999:\n",
    "                ans+=1\n",
    "            elif num==100000:\n",
    "                ans+=1\n",
    "        return ans\n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        def fc(x):\n",
    "            t = 0\n",
    "            while x:\n",
    "                t += 1\n",
    "                x //= 10\n",
    "            return 1 if t % 2 == 0 else 0\n",
    "        \n",
    "        ans = 0\n",
    "        for n in nums:\n",
    "            ans += fc(n)\n",
    "        return ans\n",
    "        \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        res=0\n",
    "        for i in nums:\n",
    "            if len(str(i))%2==0:\n",
    "                res+=1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        res = 0\n",
    "        for i in nums:\n",
    "            if len(str(i)) % 2 == 0:\n",
    "                res += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        ans = 0\n",
    "        for i in nums:\n",
    "            if len(str(i)) % 2 == 0:\n",
    "                ans += 1\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        count=0\n",
    "        for i in nums:\n",
    "            if len(str(i))%2==0:\n",
    "                count+=1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        return sum(1 for num in nums if len(str(num)) %2 == 0)\n",
    "\n",
    "\n",
    "\n",
    "            \n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        return sum(1 for num in nums if len(str(num)) % 2 == 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        return sum(1 for num in nums if int(math.log10(num) + 1) % 2 == 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        cnt = 0\n",
    "        for i in nums:\n",
    "            if len(str(i)) % 2 == 0:\n",
    "                cnt += 1\n",
    "        return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        ans = 0\n",
    "        for i in nums:\n",
    "            if len(str(i)) % 2 == 0:\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        # ans = 0\n",
    "        # for each in nums:\n",
    "        #     each = str(each)\n",
    "        #     ans += not len(each) % 2\n",
    "        # return ans\n",
    "        return sum(not len(str(each)) % 2 for each in nums)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "      count=0\n",
    "      for i in nums:\n",
    "            if len(str(i))%2==0:\n",
    "                count+=1\n",
    "      return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        i = 0\n",
    "        for data in nums:\n",
    "            if len(str(data)) % 2 == 0:\n",
    "                i += 1\n",
    "        return i \n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        count = 0\n",
    "        for i in nums:\n",
    "            if len(str(i)) % 2 == 0:\n",
    "                count += 1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        res = 0\n",
    "        for num in nums:\n",
    "            if len(str(num)) % 2 == 0:\n",
    "                res += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        count=0\n",
    "        for i in nums:\n",
    "            i=str(i)\n",
    "            if len(i)%2==0:\n",
    "                count+=1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        ans = 0\n",
    "        for i in nums:\n",
    "            if len(str(i))%2 == 0:\n",
    "                ans +=1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        n=0\n",
    "        for i in nums:\n",
    "            if len(str(i))%2==0:\n",
    "                n+=1\n",
    "        return n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        count = 0\n",
    "        for i in nums:\n",
    "            if len(str(i)) % 2 == 0:\n",
    "                count += 1\n",
    "        return count\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        result=0\n",
    "        for n in nums:\n",
    "            if 10<=n<100 or 1000<=n<10000 or 100000<=n:\n",
    "                result+=1\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        count = 0;\n",
    "        for num in nums:\n",
    "            if len(str(num)) %2 == 0:\n",
    "                count = count + 1;\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        count = 0\n",
    "        for num in nums:\n",
    "            if len(str(num)) % 2 ==0:\n",
    "                count += 1\n",
    "        return count\n",
    "# 把数字转为字符，统计个数\n",
    "\n",
    "# class Solution:\n",
    "#     def findNumbers(self, nums: List[int]) -> int:\n",
    "#         return sum(1 for num in nums if len(str(num)) % 2 == 0)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        count = 0\n",
    "        for i in range(len(nums)):\n",
    "            if len(str(nums[i])) % 2 ==0:\n",
    "                count += 1\n",
    "        return count\n",
    "# 把数字转为字符，统计个数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "    # # 方法一：循环判断\n",
    "    #     num=0\n",
    "    #     for i in nums:\n",
    "    #         if len(str(i))%2==0:\n",
    "    #             num+=1\n",
    "    #     return num\n",
    "    \n",
    "    # 方法二：简写\n",
    "        return sum(1 for num in nums if len(str(num)) % 2 == 0)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        lst = [str(i) for i in nums]\n",
    "        lst1 = [len(x) for x in lst]\n",
    "        # cnt = 0\n",
    "        # for n in lst1:\n",
    "        #     if n % 2 == 0:\n",
    "        #         cnt += 1\n",
    "        #     else:\n",
    "        #         continue\n",
    "        \n",
    "        # return cnt\n",
    "        return sum(1 for n in lst1 if n % 2 == 0)\n",
    "\n",
    "            \n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        ans = 0\n",
    "        for num in nums:\n",
    "            cnt = 0\n",
    "            while num != 0:\n",
    "                cnt += 1\n",
    "                num //= 10\n",
    "            if cnt%2 == 0:\n",
    "                ans += 1\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        '''\n",
    "        ans = 0\n",
    "        for num in nums:\n",
    "            count = 0\n",
    "            while num:\n",
    "                count += 1\n",
    "                num //= 10\n",
    "            if count%2 == 0:\n",
    "                ans += 1\n",
    "        return ans\n",
    "        '''\n",
    "        ans = 0\n",
    "        for num in nums:\n",
    "            if len(str(num))%2 == 0:\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        n=0\n",
    "        for i in nums:\n",
    "            if len(str(i))%2==0:\n",
    "                n=n+1\n",
    "        return n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "      count = 0\n",
    "      for i in range(len(nums)):\n",
    "        # 将数字强制转换成str\n",
    "        i_str = str(nums[i])\n",
    "        # 通过str的长度除2取余判断\n",
    "        if len(i_str) % 2 == 0:\n",
    "          count = count + 1\n",
    "      return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        n=0\n",
    "        for i in nums:\n",
    "            if len(str(i))%2==0:\n",
    "                n=n+1\n",
    "        return n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        res = 0\n",
    "        for i in nums:\n",
    "            if len(str(i)) % 2 == 0:\n",
    "                res += 1\n",
    "        return res\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        i = 0\n",
    "        for data in nums:\n",
    "            count = 1\n",
    "            while data >= 10:\n",
    "                data = data // 10\n",
    "                count += 1\n",
    "            if count %2 == 0:\n",
    "                i += 1\n",
    "        return i"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        ans = 0\n",
    "        for i in range(len(nums)):\n",
    "            if len(str(nums[i])) % 2 == 0:\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        f=0\n",
    "        for i in nums:\n",
    "            if len(str(i))%2==0:\n",
    "                f+=1\n",
    "        return f"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        ans = 0\n",
    "        for n in nums:\n",
    "            if 10<=n<=99 or 1000<=n<=9999 or n==100000:\n",
    "                ans+=1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        if not nums:\n",
    "            return 0\n",
    "        cnt = 0\n",
    "        for num in nums:\n",
    "            if (int(log10(num)) + 1) % 2 == 0:\n",
    "                cnt += 1\n",
    "        return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        count = 0\n",
    "        for num in nums:\n",
    "            if len(str(num)) % 2 ==0:\n",
    "                count += 1\n",
    "        return count\n",
    "# 把数字转为字符，统计个数\n",
    "\n",
    "# class Solution:\n",
    "#     def findNumbers(self, nums: List[int]) -> int:\n",
    "#        # sum对遍历列表里的nums进行if判断后的bool值求和，就得到个数\n",
    "        # return sum(1 for num in nums if len(str(num)) % 2 == 0)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        return len([_ for _ in nums if len(str(_)) % 2 == 0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        count = 0\n",
    "        for i in nums:\n",
    "            if len(str(i)) % 2 == 0:\n",
    "                count += 1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        #1.遍历数组\n",
    "        #2.判断是否为偶数\n",
    "        #3.为偶数时统计+1\n",
    "        #4.返回统计结果\n",
    "        count_num = 0\n",
    "        for i in range(len(nums)):\n",
    "           if len(str(nums[i]))%2 == 0:\n",
    "               count_num = count_num+1\n",
    "        return count_num\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        result = 0\n",
    "        for i in nums:\n",
    "            if len(str(i))%2==0:\n",
    "                result +=1\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        str_res = [str(num) for num in nums]\n",
    "        ans = 0\n",
    "        for string in str_res:\n",
    "            if len(string) % 2 == 0:\n",
    "                ans += 1\n",
    "\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        count = 0\n",
    "        for i in range(len(nums)):\n",
    "            nums[i] = str(nums[i])\n",
    "            a = len(nums[i])\n",
    "            if a % 2 == 0:\n",
    "                count += 1\n",
    "        return count\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findNumbers(self, nums: List[int]) -> int:\n",
    "        return sum(1 for num in nums if len(str(num)) % 2 == 0)"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
